#ifndef IMAGE_COLOR_BAR_H
#define IMAGE_COLOR_BAR_H

#include <QObject>
#include <QQuickPaintedItem>

namespace solar
{
    class ImageColorBar : public QQuickPaintedItem
    {
            Q_OBJECT
            Q_PROPERTY(bool item_visible MEMBER visible_ NOTIFY visibleChanged)
            Q_PROPERTY(int tick_num MEMBER tick_num_ NOTIFY tickNumChanged)
            Q_PROPERTY(float min_tick MEMBER min_tick_ NOTIFY minTickChanged)
            Q_PROPERTY(float max_tick MEMBER max_tick_ NOTIFY maxTickChanged)
            Q_PROPERTY(int font_size MEMBER font_size_ NOTIFY fontSizeChanged)
            Q_PROPERTY(int bar_width MEMBER bar_width_ NOTIFY barWidthChanged)
            Q_PROPERTY(int bar_height MEMBER bar_height_ NOTIFY barHeightChanged)

            Q_PROPERTY(int offset MEMBER offset_)

            QML_ELEMENT

        public:
            ImageColorBar(QQuickItem* parent = nullptr);
            ~ImageColorBar() override = default;

            void paint(QPainter* painter) override;

            auto getColor(float val, float min_val, float max_val) -> QColor;

        signals:
            void visibleChanged();
            void tickNumChanged();
            void minTickChanged();
            void maxTickChanged();
            void barWidthChanged();
            void barHeightChanged();
            void fontSizeChanged();

        public slots:
            Q_INVOKABLE void rePaint();
            // Q_INVOKABLE void widthAdjust();     // 根据colorbar的宽度、colorbar与tick之间的距离、

        private:
            bool visible_;

            int tick_num_;              // 标签数目
            float min_tick_, max_tick_; // 标签上的最大最小值
            int font_size_;             // 标签text大小

            int bar_width_;  // colorbar的宽度，不考虑tick
            int bar_height_; // colorbar的高度，不考虑tick

            int offset_; // 为了让tick显示完全，高度上需要有些偏移
    };
} // namespace solar

#endif
